<#import "/spring.ftl" as spring />
<#import "/inspector-time-macros.ftl" as imacro />
<html>
<head>
</head>

<body>

<link rel="stylesheet" type="text/css" href="${springMacroRequestContext.contextPath}/css/reports.css" />

<!-- Pop up calendar -->
<link rel="styleSheet" href="${springMacroRequestContext.contextPath}/css/calendarPopup.css" type="text/css">
<script src="${springMacroRequestContext.contextPath}/js/CalendarPopup.js"></script>
<script src="${springMacroRequestContext.contextPath}/js/CalendarPopup-ext.js"></script>

<div id="content">

	<h1>REAL ESTATE AGENT REPORT</h1>
	
	<div class="reportSearch">
	
		<p>To view a report of your referring real estate agents' activity, please enter a start and end date in format MM/dd/yyyy and click "GET REPORT".</p>
		
		<@imacro.listErrors "command" />
		
		<form method="post" name="searchForm">
			<div class="formElement"><label>START DATE</label>
				<div class="calendarWidget">
					<@spring.formInput "command.startDate" />
					<script>writeCalLink('document.searchForm.startDate', 'anchor1')</script>
				</div>
			</div>
			<div class="formElement"><label>END DATE</label>
				<div class="calendarWidget">
					<@spring.formInput "command.endDate" />
					<script>writeCalLink('document.searchForm.endDate', 'anchor2')</script>
				</div>
			</div>
			<br class="clearBoth" />
			<input type="hidden" name="sortBy" value="revenue" />
			<input type="submit" value="GET REPORT" class="formButton"/>
		</form>
	
	</div>
	
	<#if agentBeans??>
	
		<#if agentBeans?has_content>
		
			<div class="printReportLink"><a href="javascript:window.print()">print report</a></div>
			
			<b>AGENT REPORT FOR ${inspectorCompany.name?upper_case}
				(${command.startDate.time?string("MM/dd/yyyy")} - ${command.endDate.time?string("MM/dd/yyyy")})</b>
				
			<table class="report">
				<tr>
					<th>AGENT</th>
					<th>COMPANY</th>
					<th>OFFICE</th>
					<th class="number"><a href="#" onclick="document.searchForm.sortBy.value='inspections'; document.searchForm.submit();"># INSPECTIONS</a></th>
					<th class="currency"><a href="#" onclick="document.searchForm.sortBy.value='revenue';  document.searchForm.submit();">REVENUE</a></th>
				</tr>
				
				<#list agentBeans as agentBean>
					<tr>
						<td>${agentBean.agent.name}</td>
						<td>${agentBean.agent.company!}</td>
						<td>${agentBean.agent.office!}</td>
						<td class="number">${agentBean.numInspections}</td>
						<td class="currency">${agentBean.revenue?string.currency}</td>
					</tr>
				</#list>
				
			</table>
			
		<#else>
			<div class="noResults">No agent activity within this time frame.</div>
		</#if>
		
	</#if>
</div>

</body>
</html>